d = {'jack': 4000, 'tom': 3000, 'roy': 100}


def my_max(data_dict, key=None):
    if data_dict is None:
        return None
    larget_value = list(data_dict)[0]
    if key:
        for i in data_dict:
            if key(i) > key(larget_value):
                larget_value = i
        return larget_value

    for i in data_dict:
        if i > larget_value:
            larget_value = i
    return larget_value


res1 = my_max(d)
print('默认按key比较：',res1)
res2 = my_max(d, key=lambda k: d[k])
print('按传入匿名函数返回值比较：', res2)
